﻿
using System;

namespace SoftFloat
{
    public static partial class libm
    {
        public static sfloat PI = 3.1415926f;

        public static sfloat Acos(sfloat x) => acosf(x);

        public static sfloat Asin(sfloat x) => asinf(x);

        public static sfloat Cos(sfloat x) => cosf(x);

        public static sfloat Max(sfloat x, sfloat y) => sfloat.Max(x, y);

        public static sfloat Min(sfloat x, sfloat y) => sfloat.Min(x, y);

        public static sfloat Abs(sfloat x) => sfloat.Abs(x);

        public static sfloat Sqrt(sfloat x) => sqrtf(x);

        public static sfloat Sign(sfloat value)
        {
            if (value < 0)
                return -1;
            else if (value > 0)
                return 1;
            else if (value == 0)
                return 0;
            throw new ArgumentException("Sign BUG!");
        }

        public static sfloat Sin(sfloat x) => sinf(x);

        public static (sfloat sin, sfloat cos) SinCos(sfloat x)
        {
            var sin = Sin(x);
            var cos = Cos(x);
            return (sin, cos);
        }

        public static sfloat Clamp(sfloat value, sfloat min, sfloat max)
        {
            if (min > max)
                throw new ArgumentException("Clamp");
            if (value < min)
                return min;
            if (value > max)
                return max;
            return value;
        }

        public static int Clamp(int value, int min, int max)
        {
            if (min > max)
                throw new ArgumentException("Clamp");
            if (value < min)
                return min;
            if (value > max)
                return max;
            return value;
        }

        public static sfloat Atan2(sfloat x, sfloat y) => atan2f(x, y);
    }
}
